package cn.stylefeng.guns.modular.lx.service.impl;

import cn.stylefeng.guns.base.pojo.page.LayuiPageFactory;
import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.modular.lx.entity.LxGoodsLike;
import cn.stylefeng.guns.modular.lx.mapper.LxGoodsLikeMapper;
import cn.stylefeng.guns.modular.lx.model.params.LxGoodsLikeParam;
import cn.stylefeng.guns.modular.lx.model.result.LxGoodsLikeResult;
import  cn.stylefeng.guns.modular.lx.service.LxGoodsLikeService;
import cn.stylefeng.roses.core.reqres.response.ResponseData;
import cn.stylefeng.roses.core.util.ToolUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.List;

/**
 * <p>
 * 商品表----like 服务实现类
 * </p>
 *
 * @author like
 * @since 2023-12-20
 */
@Service
public class LxGoodsLikeServiceImpl extends ServiceImpl<LxGoodsLikeMapper, LxGoodsLike> implements LxGoodsLikeService {

    @Override
    public void add(LxGoodsLikeParam param){
        LxGoodsLike entity = getEntity(param);
        this.save(entity);
    }

    @Override
    public void delete(LxGoodsLikeParam param){
        this.removeById(getKey(param));
    }

    @Override
    public void update(LxGoodsLikeParam param){
        LxGoodsLike oldEntity = getOldEntity(param);
        LxGoodsLike newEntity = getEntity(param);
        ToolUtil.copyProperties(newEntity, oldEntity);
        this.updateById(newEntity);
    }

    @Override
    public LxGoodsLikeResult findBySpec(LxGoodsLikeParam param){
        return null;
    }

    @Override
    public List<LxGoodsLikeResult> findListBySpec(LxGoodsLikeParam param){
        return null;
    }

    @Override
    public LayuiPageInfo findPageBySpec(LxGoodsLikeParam param,String condition){
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.customPageList(pageContext, param,condition);
        return LayuiPageFactory.createPageInfo(page);
    }

    @Override
    public ResponseData upInve(int id) {
        return this.baseMapper.upInve(id);
    }

    private Serializable getKey(LxGoodsLikeParam param){
        return param.getId();
    }

    private Page getPageContext() {
        return LayuiPageFactory.defaultPage();
    }

    private LxGoodsLike getOldEntity(LxGoodsLikeParam param) {
        return this.getById(getKey(param));
    }

    private LxGoodsLike getEntity(LxGoodsLikeParam param) {
        LxGoodsLike entity = new LxGoodsLike();
        ToolUtil.copyProperties(param, entity);
        return entity;
    }

}
